<template>
  <div class="ddd">
    <div class="box" v-for="item in boxList" :key="item.id" @click="jump(item)">
      <img :src="item.s_goods_photos[0].path" alt="" />
      <div class="box-info">
        <p>{{ item.name }}</p>
        <p>{{ item.desc }}</p>
        <p>￥{{ item.price }}</p>
      </div>
    </div>
    <div class="more">
      <span>浏览更多</span>
      <i class="el-icon-right"></i>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  props: ["classid"],
  data() {
    return {
      boxList: [],
    };
  },
  methods: {
    // 点击商品跳转
    jump(item) {
      this.$router.push({
        path: "/detail",
        query: {
          id: item.id,
        },
      });
    },
  },
  created() {
    // 获取商品信息
    axios({
      method: "GET",
      url: "http://shop.bluej.cn/api/goods",
      params: {
        project_id: 90,
        status: 1,
        // 商品分组id通过父组件传入
        classify_id: this.classid,
      },
    })
      .then((res) => {
        // 接口获取的数组为倒序
        this.boxList = res.data.result.rows.reverse();
      })
      .then((err) => {
        // console.log(err);
      });
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 230px;
  height: 300px;
  background-color: #fff;
  float: left;
  position: relative;
  overflow: hidden;
  margin: 0 0 12px 12px;
  cursor: pointer;
  &:hover {
    box-shadow: 0 4px 20px 0 rgb(0 0 0 / 15%);
  }
  &:nth-child(8) {
    width: 230px;
    height: 164px;
    img {
      width: 60px;
      height: 60px;
      float: left;
      margin: 52px 24px 52px 16px;
    }
    p {
      text-align: left;
      &:first-child {
        margin: 20px auto 5px;
      }
      &:nth-child(3) {
        margin: 4px 0 8px;
      }
    }
  }
  img {
    width: 136px;
    height: 136px;
    margin: 32px auto 20px;
  }
  p {
    font-size: 12px;
    color: #666;
    line-height: 16px;
    margin: 8px 15px;
    &:first-child {
      font-size: 14px;
      color: #333;
      line-height: 20px;
    }
    &:nth-child(3) {
      margin-top: 4px;
    }
    &:last-child {
      font-size: 14px;
      color: #ff3232;
      line-height: 20px;
      margin-top: 4px;
    }
  }
}
.more {
  width: 230px;
  height: 124px;
  background-color: #fff;
  float: left;
  margin: 0 0 12px 12px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  cursor: pointer;
  &:hover {
    box-shadow: 0 4px 20px 0 rgb(0 0 0 / 15%);
  }
  span {
    font-size: 14px;
    color: #666;
    font-weight: 700;
  }
}
</style>